<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/mytag.jspf"%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>用户</title>
<script type="text/javascript">
if('${t.purpose}'=="SRGH"){$("#divId").hide();}
$("#purpose").change(function(){
	if($(this).val()=="SRGH"){
		$("#type").val("TP");
		$("#divId").hide();
	}
	if($(this).val()=="KQ"){
		$("#type").val("TW");
		$("#divId").show();
	}
});
function upImage(){
	$("#imgForm").ajaxSubmit({
		dataType : "json",
		success : function(data) {
			if (data.success == true) {
				var url = data.msg;
				$("#imgId").attr("src",url);
				$("#img").val(url);
			} else {
				alert(data.msg);
			}
		}
	});
}
$(function(){
	$("#form").validate({
		rules : {
			"purpose" : {
				required : true,
				remote : { // 异步验证是否存在
					type : "POST",
					url : 'management/material/isExist',
					data : {
						type : function() {
							return $("#purpose").val();
						},
						id : function() {
							return $("#materialId").val();
						}
					}
				}
			},
			"name" : {
				required : true
			},
			"shopName" : {
				required : true
			},
			"title" : {
				required : true
			},
			"content" : {
				required : true
			},
			"summary" : {
				required : true
			}
		},
		messages : {
			"purpose" : {
				required : "请选择类型",
				remote : "生日关怀类型已经存在一条记录，该类型有且只能有一条记录"
			},
			"shopName" : {
				required : "请选择门店"
			},
			"title" : {
				required : "请填写素材标题"
			},
			"content" : {
				required : "请填写素材内容"
			},
			"summary" : {
				required : "请填写素材摘要"
			}
		}
	});
	
	
	$("#submitBtn").on("click",function(){
		$("#form").submit();
	});
});
</script>
</head>
<body>
	<ol class="am-breadcrumb am-breadcrumb-slash am-padding" style="margin-bottom: 0px;">
		<li><a href="management/index">首页</a></li>
		<li><a href="management/material/index">素材信息维护</a></li>
		<li class="am-active">修改</li>
	</ol>
	<div class="am-g">
		<div class="am-u-md-12">
				<div class="am-tabs am-margin">
					<ul class="am-tabs-nav am-nav am-nav-tabs">
						<li class="am-active"><a href="javascript:void(0)">基本信息</a></li>
					</ul>
					<div class="am-tabs-bd">
						<div class="am-tab-panel am-active">
							<div>
								<div class="am-u-sm-12">
									<form id="imgForm"  class="am-form am-form-horizontal am-block" action="management/file" method="post" enctype="multipart/form-data">	
										<label class="am-u-sm-2 am-form-label">素材图片</label>
										<div class="am-u-md-4 am-u-end">
												<c:if test="${empty t.img }">
												<img id="imgId" src="file/a.png" class="am-form-field am-input-sm">
												</c:if>
												<c:if test="${!empty t.img }">
													<img id="imgId" src="${t.img }" class="am-form-field am-input-sm">
												</c:if>
												<div class="am-form-group am-form-file">
												  <button type="button" class="am-btn am-btn-default am-btn-sm">
												    <i class="am-icon-cloud-upload"></i> 选择要上传的图片</button>
												  <input name="imageFile" id="imageFile"  onchange="upImage();" type="file" multiple>
												</div>
										</div>
									</form>
								</div>	
								<div class="am-u-sm-12">
									<form class="am-form am-form-horizontal" id="form" name="form"  method="post" action="management/material/update">
										<input type="hidden" name="img" id="img" value="${t.img }" class="am-form-field am-input-sm">
										<input type="hidden" name="compId" id="compId" value="${t.compId }" class="am-form-field am-input-sm">
										<input type="hidden" name="mediaId" id="mediaId" value="${t.mediaId }" class="am-form-field am-input-sm">
										<input type="hidden" name="materialId" id="materialId" value="${t.materialId }" class="am-form-field am-input-sm">
										<div class="am-form-group">
											<label class="am-u-sm-2 am-form-label">素材名称</label>
											<div class="am-u-md-4 am-u-end">
												<input type="text" id="name" name="name"  value="${t.name }" maxlength="100" class="am-form-field am-input-sm">
											</div>
										</div>
										<div class="am-form-group">
											<label class="am-u-sm-2 am-form-label">素材用途</label>
											<div class="am-u-md-4 am-u-end">
												<t:dictSelect tabName="MATERIAL" colName="PURPOSE" field="purpose" id="purpose" defaultVal="${t.purpose}"></t:dictSelect>
												<input type="hidden" name="type" id="type" value="${t.type }" class="am-form-field am-input-sm">
											</div>
										</div>
										<div id="divId">
										<div class="am-form-group">
											<label class="am-u-sm-2 am-form-label">素材标题</label>
											<div class="am-u-md-4 am-u-end">
												<input type="text" id="title" name="title"  value="${t.title }" maxlength="50" class="am-form-field am-input-sm">
											</div>
										</div>
										<div class="am-form-group">
											<label class="am-u-sm-2 am-form-label">素材内容</label>
											<div class="am-u-md-4 am-u-end">
												<textarea id="content" name="content"  maxlength="120" class="am-form-field am-input-sm">${t.content }</textarea>
											</div>
										</div>
										<div class="am-form-group">
											<label class="am-u-sm-2 am-form-label">素材摘要</label>
											<div class="am-u-md-4 am-u-end">
												<textarea id="summary" name="summary"  maxlength="120" class="am-form-field am-input-sm">${t.summary }</textarea>
											</div>
										</div>
										</div>
										
									</form>	
								</div>
							</div>	
						</div>
					</div>
				</div>
				<div class="am-margin">
					<button class="am-btn am-btn-primary am-btn-xs" type="button" id="submitBtn"><span class="am-icon-check"></span> 保存</button>
					<a href="javascript:;" onClick="javascript:history.back(-1);" class="am-btn am-btn-primary am-btn-xs"><span class="am-icon-times"></span> 取消</a>
				</div>
		</div>
	</div>
</body>
</html>
